package com.tg.app.report;

import com.tange.base.toolkit.DateUtil;
import com.tg.app.util.LogUtils;

import java.util.HashMap;

public class DeviceAddReport {
    private DeviceAddReportBean reportBean;

    public void setReportBean(DeviceAddReportBean reportBean) {
        this.reportBean = reportBean;
    }

    public DeviceAddReportBean getReportBean() {
        return reportBean;
    }

    private static   DeviceAddReport addReport;
    public static DeviceAddReport getInstance() {
        if (addReport==null){
            addReport = new DeviceAddReport();
        }
        return addReport;
    }

    public void upload(){
        if (reportBean!=null){
            HashMap<String,String>  hashMap= new HashMap<>();
            hashMap.put("name",reportBean.name);
            hashMap.put("title",reportBean.title);
            hashMap.put("uuid",reportBean.uuid);
            hashMap.put("user_id",reportBean.userID);
            if (reportBean.startTime>0){
                hashMap.put("start_time", DateUtil.getStrToTime(reportBean.startTime));
            }
            if (reportBean.endTime>0){
                hashMap.put("end_time", DateUtil.getStrToTime(reportBean.endTime));
                long sec = (reportBean.endTime-reportBean.startTime)/1000;
                hashMap.put("used_seconds",String.valueOf(sec));
            }
            hashMap.put("result",reportBean.isSucceed?"succeed":"failed");
            if (reportBean.isSucceed){
                hashMap.put("end_time", DateUtil.getStrToTime(reportBean.endTime));
            }
            if (reportBean.connectLoadStart>0){
                hashMap.put("loading_start_time", DateUtil.getStrToTime(reportBean.connectLoadStart));
            }
            if (reportBean.connectLoadEnd>0){
                hashMap.put("loading_end_time", DateUtil.getStrToTime(reportBean.connectLoadEnd));
                long sec = (reportBean.connectLoadEnd-reportBean.connectLoadStart)/1000;
                hashMap.put("loading_used_seconds",String.valueOf(sec));
            }
            if (reportBean.connectWifiStart>0){
                hashMap.put("connect_device_wifi_start", DateUtil.getStrToTime(reportBean.connectWifiStart));
            }
            if (reportBean.connectWifiEnd>0){
                hashMap.put("connect_device_wifi_end", DateUtil.getStrToTime(reportBean.connectWifiEnd));
                long sec = (reportBean.connectWifiEnd-reportBean.connectWifiStart)/1000;
                hashMap.put("connect_device_wifi_used_seconds",String.valueOf(sec));
            }
            hashMap.put("opened_system_config",reportBean.isConfingWifi==1?"yes":"no");
            LogUtils.uploadLog(hashMap);
        }
    }

}
